package initialize

import (
	"fmt"
	"gin-vue-admin/global"

	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type IfnRegisterRouter = func(publicRouterGroup *gin.RouterGroup, privateRouterGroup *gin.RouterGroup)

var (
	registerRouter []IfnRegisterRouter
)

func InitRouter() *gin.Engine {
	// 创建gin服务
	ginServer := gin.Default()
	// 路由组统一放在这里注册
	//systemRouter := router.RouterGroupApp
	global.LOG.Info("router register success")
	return ginServer
	// 创建监听ctrl+c应用退出信号的上下文
}

func RunServer() {
	// 初始化路由
	Router := InitRouter()
	address := fmt.Sprintf(":%d", global.CONFIG.System.Port)
	// 启动HTTP服务
	s := initServer(address, Router)
	global.LOG.Debug("server run success", zap.String("port", address))
	s.ListenAndServe().Error()
	global.LOG.Info("server start complete ")
}
